from xml.parsers.expat import ParserCreate
path = r"C:\Users\GJ\Desktop\web.config"

import sys

class default_hander(object):
	def handle_start_element(self, name, attrs):
		print("sap: handle_start_element >>> name:" + name, "attrs:",attrs)

	def handle_end_element(self, name):
		print("sax: handle_end_element >>> name:", name)

	def handle_character_data(self, text):
		print("sax: handle_character_data >>>" + text)


handler = default_hander()

parser = ParserCreate()
parser.StartElementHandler = handler.handle_start_element
parser.EndElementHandler = handler.handle_end_element
parser.CharacterDataHandler = handler.handle_character_data

with open(path,"r", encoding="utf-8") as f:
	data = f.read()
	parser.Parse(data)

